package org.hhchat.leetcode.hashtable;

import java.util.HashMap;

public class code594_easy {

    static class Solution {
        public int findLHS(int[] nums) {
            HashMap<Integer, Integer> hashMap = new HashMap<>();
            for(int num:nums){
                hashMap.put(num, hashMap.getOrDefault(num, 0) + 1);
            }
            int max = 0,result;
            for (Integer key : hashMap.keySet()) {
                if(hashMap.containsKey(key+1)){
                    result = hashMap.get(key) + hashMap.get(key + 1);
                    max = Integer.max(result, max);
                }
            }
            return max;
        }
    }

    public static void main(String[] args) {

    }
}
